using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ResourceBlender_Express {
    /// <summary>
    /// A generic dialog which prompts for input.
    /// </summary>
    public partial class WinInputDialog : Window {
        public delegate bool ValidateDelegate();
        public event ValidateDelegate ValidateInput;

        /// <summary>
        /// Gets or sets the text entered.
        /// </summary>
        /// <value>The user input.</value>
        public string UserInput {
            get { return txtInput.Text; }
            set { txtInput.Text = value; }
        }

        /// <summary>
        /// Initializes a new <see cref="WinInputDialog"/>.
        /// </summary>
        /// <param name="caption">The window caption.</param>
        /// <param name="message">The message prompt displayed.</param>
        public WinInputDialog(string caption, string message) {
            InitializeComponent();
            this.Title = caption;
            this.txtDisplayMessage.Text = message;
            txtInput.Focus();
        }

        /// <summary>
        /// Calls the delegate listening for the ValidateInput event if one is registers, then returns a DialogResult of true.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnOk_Click(object sender, RoutedEventArgs e) {
            if(ValidateInput != null) {
                if(ValidateInput()) {
                    this.DialogResult = true;
                }
            } else {
                this.DialogResult = true;
            }
        }
    }
}
